<?php
include 'config.php';
include 'common.php';

require "vendor/autoload.php";
use Gaoming13\WechatPhpSdk\Wechat;
use Gaoming13\WechatPhpSdk\Api;


// AppID(应用ID)
$appId = $config['AppId'];
// AppSecret(应用密钥)
$appSecret = $config['AppSecret'];
// Token(令牌)
$token = 'e10adc3949ba59a';
// EncodingAESKey(消息加解密密钥)
$encodingAESKey = 'Zk55c271FPhOWi7igIWg0pezuUpDxnHZ41e6RFtfPn5';

// wechat模块 - 处理用户发送的消息和回复消息
$wechat = new Wechat(array(
    'appId' => $appId,
    'token' => 	$token,
    'encodingAESKey' =>	$encodingAESKey
));
// 获取微信消息
$msg = $wechat->serve();

// api模块 - 包含各种系统主动发起的功能
$api = new Api(
    array(
        'appId' => $appId,
        'appSecret'	=> $appSecret,
    )
);


if($msg->MsgType == "event" && $msg->Event == "subscribe") {

    $user = $api->get_user_info($msg->FromUserName);
    file_get_contents("https://api.mxzhuawawa.com/OpenAPI/v1/user/userSubscribeCoin?unionid=".$user[1]->unionid);



    $wechat->reply("首次关注公众号就有50金币哦，关注公众号后直接点击下方“抓娃娃”登录进游戏中就有咯，您可以刷新看看，消息中心也是有消息提示的哦

大转盘的活动：进入游戏界面左侧有个抽奖的入口就是啦，百分百中奖的呦，每天都至少有一次的抽奖机会，是时候展现你们真正的实（yun）力（qi）了，咔咔咔~

注：关注公众号和大转盘所获得的金币都会及时到账，而且消息中心也会有消息提示的哦，您可以去查看，如果出现金币未到账的情况，请耐心等待或刷新下，也可尝试退出再登录，如有问题请联系在线客服（登录进入游戏-个人中心-在线客服）！");
}




exit;




$res = $api->create_menu('{
    "button": [
        {
            "type": "view",
            "name": "抓娃娃",
            "url": "https://m.mxzhuawawa.com"
        },
        {
            "type": "view",
            "name": "充值",
            "url": "https://m.mxzhuawawa.com/recharge.html"
        },
        {
            "name": "更多",
            "sub_button": [
                {
                    "type": "view",
                    "name": "安卓下载",
                    "url": "http://sj.qq.com/myapp/detail.htm?apkName=com.mxzhuawawa.app"
                }
            ]
        }
    ]
}');
